package com.zhongya.example.adapter

import android.view.MotionEvent
import android.view.View
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zhongya.example.R

class Part7AdapterItemTouchHelper : BaseQuickAdapter<String,BaseViewHolder>(R.layout.example_item_part7_itemtouchhelper) {

    var listener : (BaseViewHolder) -> Unit = {}

    fun setDragListener(listener : (BaseViewHolder) -> Unit){
        this.listener = listener
    }

    override fun convert(holder: BaseViewHolder, item: String) {
        holder.getView<TextView>(R.id.tv_content).text = item
        holder.getView<View>(R.id.iv).setOnTouchListener { v, event ->
            if (event.actionMasked == MotionEvent.ACTION_DOWN){
                listener.invoke(holder)
            }
            false
        }
    }
}